while.ion 693 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Simple While Loop
  2. let a = 1
  3. while test $a -lt 10
  4. echo $a
  5. let a += 1
  6. end
  7. # While Loop With If Conditions
  8. let a = 1
  9. while test $a -lt 10
  10. if test $a -eq 5
  11. echo found 5
  12. else
  13. echo $a
  14. end
  15. let a += 1
  16. end
  17. # Nested While Loops
  18. let outer_count = 1;
  19. while test $outer_count -lt 4
  20. echo "outer loop #$outer_count"
  21. let outer_count += 1
  22. let inner_count = 1
  23. while test $inner_count -lt 4
  24. echo " inner loop #$inner_count"
  25. let inner_count += 1
  26. end
  27. end
  28. # Chained predicates
  29. let first = 1
  30. let second = 1
  31. while test $first -lt 13 && test $second -lt 20
  32. echo $first $second
  33. let first second = $second $((first + second))
  34. end