looping problems
Author |
Message |
L337User
|
Posted: Sun Jan 18, 2009 4:24 pm Post subject: looping problems |
|
|
This is a chunk of shape program i have to do for an ISP when i ask for choice near the end i want it to exit the outermost loop not just the one it is embedded if thye input shape does anyone have any suggestions?
Turing: | elsif shape = "parallelogram" then
put "What part would you like to solve for"
put "base, height, or area"
get partpara
loop
if partpara = "base" then
put "Please enter the height THEN area"
get height
get area
put "The equation we will be using is Base = Area / height"
put "B = A/h This is our base equation"
put "B = ", area / height, " This equation simply requires you to divide"
put "Therefore B = ", area / height
exit
elsif partpara = "height" then
put "Please enter base THEN area"
get base
get area
put "The equation we will be using is Height = Area / base"
put "h = A/b This is our base equation"
put "h = ", area / base, " This equation simply requires you to divide"
put "Therefore the height is ", area / base
exit
elsif partpara = "area" then
put "Please enter base THEN height"
get base
get height
put "The equation we will be using is Area = base * height"
put "A = b*h This is our base equation"
put "A = ", base * height, " This equation simply requires you to divide"
put "Therefore the area is ", base * height
exit
else
put "That is not a valid part please re-enter the part and check your spelling and make sure all characters lower case"
get partpara
end if
end loop
put "Please type in shape if you want to solve for another shape or part if you want to solve for another part"
get choice
loop
if choice = "shape" then
exit
elsif choice = "part" then
exit
else
put "That is an invalid answer please retype and make sure it is lower case and properly spelt"
end if
end loop
|
Mod Edit: Fixing broken syntax tag |
|
|
|
|
|
Sponsor Sponsor
|
|
|
L337User
|
Posted: Sun Jan 18, 2009 4:26 pm Post subject: RE:looping problems |
|
|
sorry i havent worked out how to do that syntax thing yet |
|
|
|
|
|
L337User
|
Posted: Sun Jan 18, 2009 4:35 pm Post subject: RE:looping problems |
|
|
Turing: |
elsif shape = "parallelogram" then
put "What part would you like to solve for"
put "base, height, or area"
get partpara
loop
if partpara = "base" then
put "Please enter the height THEN area"
get height
get area
put "The equation we will be using is Base = Area / height"
put "B = A/h This is our base equation"
put "B = ", area / height, " This equation simply requires you to divide"
put "Therefore B = ", area / height
exit
elsif partpara = "height" then
put "Please enter base THEN area"
get base
get area
put "The equation we will be using is Height = Area / base"
put "h = A/b This is our base equation"
put "h = ", area / base, " This equation simply requires you to divide"
put "Therefore the height is ", area / base
exit
elsif partpara = "area" then
put "Please enter base THEN height"
get base
get height
put "The equation we will be using is Area = base * height"
put "A = b*h This is our base equation"
put "A = ", base * height, " This equation simply requires you to divide"
put "Therefore the area is ", base * height
exit
else
put "That is not a valid part please re-enter the part and check your spelling and make sure all characters lower case"
get partpara
end if
end loop
put "Please type in shape if you want to solve for another shape or part if you want to solve for another part"
get choice
loop
if choice = "shape" then
exit
elsif choice = "part" then
exit
else
put "That is an invalid answer please retype and make sure it is lower case and properly spelt"
end if
end loop
|
sorry no i have it |
|
|
|
|
|
andrew.
|
Posted: Sun Jan 18, 2009 5:34 pm Post subject: RE:looping problems |
|
|
You just do this:
code: | [syntax="Turing"]% Your Code Here[/syntax] |
Just copy and paste your code where it says your code here. |
|
|
|
|
|
DemonWasp
|
Posted: Mon Jan 19, 2009 10:57 am Post subject: RE:looping problems |
|
|
To exit from multiple loops in Turing, you will need to use an exit flag and some "exit when" statements. Example:
Turing: |
loop
var doExit : boolean := false
loop
% some stuff goes here. Oops, we should exit!
doExit := true
exit
end loop
exit when doExit
end loop
|
|
|
|
|
|
|
|
|