CPS 393 Lecture Notes - Lecture 4: Infinite Loop, While Loop, Texas State Highway Loop 1

104 views5 pages

Document Summary

Lecture 4: loops, variable scope, regex, brog style lecture. While loop: typical conditional loop syntax: while command(s) do actions done. # example 1 month=1 while [ -le 12 ] # le is a less than or equal to operator do someprocess month=1 # $ with double parentheses means an arithmetic expression - Treats the stuff inside as numbers done. # example 2 --- incorrect version while read wholeline < inputfile do someaction done. # so you only read the 1st again repeatedly. # example 2 --- correct version while read wholeline # reads everything upto (not including) the newline char do echo done < inputfile. # we are only opening the file once. # whenever the read command is run in this case, # it continues reading 1 line at a time till the end of the file. # it exits the body of the loop.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents