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 8758341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:31:21+00:00 2026-06-13T14:31:21+00:00

I have problem trying to make for each loop in C++. I’m not certain

  • 0

I have problem trying to make for each loop in C++. I’m not certain is this is possible in C++ if it is I still dont know to make it.

I have one simple problem written in pascal that does finding of the day in year when it is a friday 13 or saturday 25 no metter which day.

In pascal I have code like this:

{First I declare types}
type
    months = (January, February, March, April, May, June, July, August, September, October, November, December);
...
{Then I declare variable for months}
var
    m: mesec;
...
{Then I can declare for loop that will loop over months}
for m:= januar to december do
...

The similar way of doing a for each loop over enumerations is possible in python too.
My question is:

Is there any way of doing for or even while loop over enumerations in C++?

I know this may seem as a beginers question but I tried on few different ways to do it doesnt work. Doesnt compile.

  • 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-13T14:31:23+00:00Added an answer on June 13, 2026 at 2:31 pm

    No, you can’t do this directly in C++. There are a few workarounds, though.

    • If the values of the enum are increased by 1 (i.e. have consecutive values, as they do by default, in case you don’t explicitly set their values), you can use them as normal ints, and increase the cycle variable by 1 each time until it equals the last enum‘s value. This is described in this SO question.
    • If the values are not increasing by 1 (e.g. enum E {FIRST = 5, SECOND = 10}, it becomes more tricky. You could make an array holding all possible values and use it (that’s a crappy solution, but it works):

      enum E
      {
          FIVE = 5,
          TEN = 10,
          THREE = 3
      };
      E arr[3] = {FIVE,TEN,THREE};
      E iterator;
      for( int i = 0; i < 3; i++ )
      {
          iterator = arr[i];
          //do something with it
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make simple minesweeper game in python, but have one problem. I have
I have a huge problem with this method im trying to make. I have
I have a problem when trying to execute this update statement (below) using C#
Well I have been trying this problem for over 10 hours and have no
I have a problem trying to turn my python code into an executable using
I have a problem trying to register my own Event/Listener to the event dispatcher.
I have a problem trying to design some generic storage.. Basically I have the
I have a problem trying to edit. I work with Areas for better management
I have a problem trying to hide .php extension from the url I have
I implemented the table sorter yesterday and i have a problem trying to change

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.