 |
|
BaselScript |
Beschreibung
Menu
▀ ▀ ▀ ▀ JAVA ▀ ▀ ▀ ▀
import java.util.Scanner;
public class MenuDrivenProgram {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("---- Menu ----");
System.out.println("1. Option 1");
System.out.println("2. Option 2");
System.out.println("3. Option 3");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.println("You selected Option 1");
// Add your code for Option 1 here
break;
case 2:
System.out.println("You selected Option 2");
// Add your code for Option 2 here
break;
case 3:
System.out.println("You selected Option 3");
// Add your code for Option 3 here
break;
case 4:
System.out.println("Exiting the program.");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please select a valid option.");
}
}
}
}
▀ ▀ ▀ ▀ KOTLIN ▀ ▀ ▀ ▀
import java.util.Scanner
fun main() {
val scanner = Scanner(System.`in`)
while (true) {
println("---- Menu ----")
println("1. Option 1")
println("2. Option 2")
println("3. Option 3")
println("4. Exit")
print("Enter your choice: ")
when (scanner.nextInt()) {
1 -> {
println("You selected Option 1")
// Add your code for Option 1 here
}
2 -> {
println("You selected Option 2")
// Add your code for Option 2 here
}
3 -> {
println("You selected Option 3")
// Add your code for Option 3 here
}
4 -> {
println("Exiting the program.")
return
}
else -> println("Invalid choice. Please select a valid option.")
}
}
}
▀ ▀ ▀ ▀ PYTHON ▀ ▀ ▀ ▀
while True:
print("---- Menu ----")
print("1. Option 1")
print("2. Option 2")
print("3. Option 3")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == "1":
print("You selected Option 1")
# Add your code for Option 1 here
elif choice == "2":
print("You selected Option 2")
# Add your code for Option 2 here
elif choice == "3":
print("You selected Option 3")
# Add your code for Option 3 here
elif choice == "4":
print("Exiting the program.")
break
else:
print("Invalid choice. Please select a valid option.")
▀ ▀ ▀ ▀ DELPHI ▀ ▀ ▀ ▀
program MenuDrivenProgram;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
choice: Integer;
begin
while True do
begin
WriteLn(`---- Menu ----`);
WriteLn(`1. Option 1`);
WriteLn(`2. Option 2`);
WriteLn(`3. Option 3`);
WriteLn(`4. Exit`);
Write(`Enter your choice: `);
ReadLn(choice);
case choice of
1:
begin
WriteLn(`You selected Option 1`);
// Add your code for Option 1 here
end;
2:
begin
WriteLn(`You selected Option 2`);
// Add your code for Option 2 here
end;
3:
begin
WriteLn(`You selected Option 3`);
// Add your code for Option 3 here
end;
4:
begin
WriteLn(`Exiting the program.`);
Exit;
end;
else
WriteLn(`Invalid choice. Please select a valid option.`);
end;
end;
end.
▀ ▀ ▀ ▀ BASEL SCRIPT ▀ ▀ ▀ ▀
scene=1 name="menu"
// start script
section init
call menu = menu1
end
// define menu
menu menu1
tile=title text= "Enter your choice:"
tile=item text="1. Option 1" action=opt1
tile=item text="2. Option 2" action=opt2
tile=item text="back" section=back
end menu
// opt1 selected
action opt1
message "option1"
end
// opt2 selected
action opt2
message "option2"
end
// back was pressed
action back
exit from app
end
end scene 1