Uses of selection in programming (if, switch etc)

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I am an experienced programmer that has just started teaching. I am struggling to see how to introduce selection to my programming classes. None of the examples that I have seen so far are good.

I am struggling to find examples other than the ones below. (These are more advanced than I need.)

  • Termination condition for recursion (We don't do recursion until upper years of school, exams do not need it).

  • Input validation (Again the exams say don't worry about checking input (I think this is a mistake, as it leads to cowboy programmers)).

Both of these are only in the syllabus from UK year 12. I am teaching from UK year 7.

Can you help with good examples, and exercises that my younger pupils can use?


year 7 is age 11-12 year 12 is age 16-17

profilepic.png
manpreet 2 years ago

There are endless examples that illustrate selection. As you know, most useful programs have at least one selection statement. I've found that some students struggle with the concept, so I start small and pick examples that resonate with students, for example:

    if (hungry)
        System.out.println("Eat a sandwich.");

    if (age > 17)
        System.out.println("You can vote.");
    else
        System.out.println("You cannot vote.");

For a switch statement, I like to show some type of menu:

    switch(choice) {
    case 0:
        System.out.println("Balance Inquiry.");
        break;
    case 1:
        System.out.println("Transfer");
        break;
    case 2:
        System.out.println("Withdrawal");
        break;  
    case 3:
        System.out.println("Deposit");
        break;          
    default:
        System.out.println("Quit");
        break;          
    }

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.