/**
 * Write a function that takes a string parameter and counts the number of words in the text using a while loop.
 * Return the total number of words.
 *
 * Example:
 * countWordsInText("Hello, how are you?") --> 5
 */
fun countWordsInText(text: String): Int {

    var count = 0
    var index = 0

    while (index < text.length) {
        if (text[index] == ' ' || text[index] in setOf(',', '.', '!', '?', ';', ':')) {
            if (index + 1 < text.length && (text[index + 1].isLetterOrDigit() || text[index + 1] in setOf(',', '.', '!', '?', ';', ':'))) {
                count++
            }
        }
        index++
    }

    return count
}
/**
 * Write a function that takes a string parameter and counts the number of words in the text using a while loop.
 * Return the total number of words.
 *
 * Example:
 * countWordsInText("Hello, how are you?") --> 5
 */
fun countWordsInText(text: String): Int {
/**
 * Write a function that takes a string parameter and counts the number of words in the text using a while loop.
 * Return the total number of words.
 *
 * Example:
 * countWordsInText("Hello, how are you?") --> 5
 */
fun countWordsInText(text: String): Int {

    var count = 0
    var index = 0

    while (index < text.length) {
        if (text[index] == ' ' || text[index] in setOf(',', '.', '!', '?', ';', ':')) {
            if (index + 1 < text.length && (text[index + 1].isLetterOrDigit() || text[index + 1] in setOf(',', '.', '!', '?', ';', ':'))) {
                count++
            }
        }
        index++
    }

    return count
}