How to resolve the algorithm Jump anywhere step by step in the i programming language
How to resolve the algorithm Jump anywhere step by step in the i programming language
Table of Contents
Problem Statement
Imperative programs like to jump around, but some languages restrict these jumps. Many structured languages restrict their conditional structures and loops to local jumps within a function. Some assembly languages limit certain jumps or branches to a small range. This task is to demonstrate a local jump and a global jump and the various other types of jumps that the language supports. For the purpose of this task, the jumps need not be used for a single purpose and you have the freedom to use these jumps for different purposes. You may also defer to more specific tasks, like Exceptions or Generator. This task provides a "grab bag" for several types of jumps. There are non-local jumps across function calls, or long jumps to anywhere within a program. Anywhere means not only to the tops of functions! These jumps are not all alike. A simple goto never touches the call stack. A continuation saves the call stack, so you can continue a function call after it ends.
Use your language to demonstrate the various types of jumps that it supports. Because the possibilities vary by language, this task is not specific. You have the freedom to use these jumps for different purposes. You may also defer to more specific tasks, like Exceptions or Generator.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Jump anywhere step by step in the i programming language
Source code in the i programming language
//'i' does not have goto statements, instead control flow is the only legal way to navigate the program.
concept there() {
print("Hello there")
return //The return statement goes back to where the function was called.
print("Not here")
}
software {
loop {
break //This breaks the loop, the code after the loop block will be executed next.
print("This will never print")
}
loop {
loop {
loop {
break //This breaks out of 1 loop.
}
print("This will print")
break 2 //This breaks out of 2 loops.
}
print("This will not print")
}
//Move to the code contained in the 'there' function.
there()
}
You may also check:How to resolve the algorithm Extensible prime generator step by step in the Haskell programming language
You may also check:How to resolve the algorithm Guess the number step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Determine if a string is collapsible step by step in the R programming language
You may also check:How to resolve the algorithm Compiler/syntax analyzer step by step in the Forth programming language
You may also check:How to resolve the algorithm Closest-pair problem step by step in the BASIC programming language