Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:29:50+00:00 2026-06-01T04:29:50+00:00

i need to show a menu that derive another menu and this derive another

  • 0

i need to show a menu that derive another menu and this derive another menu.
But i’m validating those menus with this form: (Only C standard library)

do{
    validOption = 1;
    printf("Option #1\n");
    printf("Option #2\n");
    printf("Option #3\n");
    scanf("%i",&option);
    switch(option){
        case 1: /* Do something */ break;
        case 2: /* Do something */ break;
        case 3: /* Do something */ break;
        default: validOption = 0; printf("Invalid Option\n"); break;
    }
}while(!validOption);

But at the time of derive a menu i dont know if use the same option variable and validOption flag.
I think that is not a problem since the derived option variable is going to be overwritten and
I will not need the previous option variable since that option variable has been used for its only
purpose that is join in a specific case.
Now, validOption flag is not a problem too, since when a successfully case occurs means that validOption = 1 (will not iterate more)
and it will match with the previous validOption that have a value of 1 (since has been joined in a case). So will not interfere.

Is a good practice to use the same variables (option, validOption) within derived menus?

Also i need to validate with a getint() function, which make me think that if
is even necessary validate menus seeing it in a practical way.

#include<stdio.h>
int main(){
    int option;
    int validOption;
    do{
        printf("Option #1\n");
        printf("Option #2\n");
        printf("Option #3\n");
        scanf("%i",&option);
        switch(option){
            case 1:
                validOption = 1;
                do{
                    printf("Option #1\n");
                    printf("Option #2\n");
                    printf("Option #3\n");
                    scanf("%i",&option);
                    switch(option){
                        case 1:  validOption = 1; /* Another menu with the same option and validOption variables */ break;
                        case 2:  validOption = 1; /* Do something */ break;
                        case 3:  validOption = 1; /* Do something */ break;
                        default: validOption = 0; printf("Invalid Option\n"); break;
                    }
                }while(!validOption);
            break;
            case 2:  validOption = 1; /* Do something */ break;
            case 3:  validOption = 1; /* Do something */ break;
            default: validOption = 0; printf("Invalid Option\n"); break;
        }
    }while(!validOption);
    return 0;
}
//I've put validOption = 1; within all cases just for explaining purposes
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:29:52+00:00Added an answer on June 1, 2026 at 4:29 am

    I would rather call it nested loop than derived.

    Coming to your question: Is it valid to re-use same variable within a loop when the 1st value of the variable is no longer needed? (Am I right in rephrasing your question?)

    Yes, it’s valid. While there’s nothing technically wrong with it, I would say No. Because, it causes unnecessary confusion and makes the code readability difficult especially when you it within the same loop (as you do within your outer loop). It becomes even harder as the code base grows. Hence, I would discourage such a coding practice.

    You want to validate your integer: Since, you are only going to do pass-by-value (to getint()), there’s no problem in using another variable. You can use option1 and option2

    Pass the values to getint() to validate it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a QTableView , and i need to show a popup menu that
I need help, I need to make a menu that only shows when you
I need to create a menu that will show all files in USB. The
i got this requirement, i need to show my Flash Menu into the index
I have a dropdown menu that works fine, but I would like it so,
I have this drop down menu that when one menu is clicked if there
I need to show x number of cateogories in a menu (basically a hidden
I would love to use wordpress built in menu system and I need sub-menus.
I am trying to build a drop-down menu that will show a row to
So I have this menu and when I click on a button I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.