/**
 * Given a list 'data', a starting index 'start', and an ending index 'end',
 * this function should return a new list containing the elements between 'start' and 'end'
 * in the original list. Additionally, the function should iterate over the new list
 * and print each element.
 *
 * @param data The original list of elements.
 * @param start The starting index of the slice.
 * @param end The ending index of the slice.
 * @return The new list containing the sliced elements.
 *
 * Example:
 * val data = listOf("apple", "banana", "cherry", "dates")
 * sliceAndIterate(data, 1, 3)
 * Output:
 * banana
 * cherry
 */
fun sliceAndIterate(data: List<String>, start: Int, end: Int): List<String> {

    val slicedList = data.subList(start, end)

    for (element in slicedList) {
        println(element)
    }

    return slicedList
}
/**
 * Given a list 'data', a starting index 'start', and an ending index 'end',
 * this function should return a new list containing the elements between 'start' and 'end'
 * in the original list. Additionally, the function should iterate over the new list
 * and print each element.
 *
 * @param data The original list of elements.
 * @param start The starting index of the slice.
 * @param end The ending index of the slice.
 * @return The new list containing the sliced elements.
 *
 * Example:
 * val data = listOf("apple", "banana", "cherry", "dates")
 * sliceAndIterate(data, 1, 3)
 * Output:
 * banana
 * cherry
 */
fun sliceAndIterate(data: List<String>, start: Int, end: Int): List<String> {
/**
 * Given a list 'data', a starting index 'start', and an ending index 'end',
 * this function should return a new list containing the elements between 'start' and 'end'
 * in the original list. Additionally, the function should iterate over the new list
 * and print each element.
 *
 * @param data The original list of elements.
 * @param start The starting index of the slice.
 * @param end The ending index of the slice.
 * @return The new list containing the sliced elements.
 *
 * Example:
 * val data = listOf("apple", "banana", "cherry", "dates")
 * sliceAndIterate(data, 1, 3)
 * Output:
 * banana
 * cherry
 */
fun sliceAndIterate(data: List<String>, start: Int, end: Int): List<String> {

    val slicedList = data.subList(start, end)

    for (element in slicedList) {
        println(element)
    }

    return slicedList
}