Author Topic: Using 'loops' in a Class  (Read 3370 times)


  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Using 'loops' in a Class
« on: February 21, 2017, 03:30:51 am »
I wanted to ask a general programing question that has had me puzzled still to this day, Even while studying C++.

Is it bad to run a while loop, Or any loop for that mater anywhere within a class?

I am sure that 'maybe' it depends on the programing language.

I find using a loop inside a class to be highly useful in general, I do not see it being a bad thing what so ever, But I could see where it could. Just curious honestly  :)


  • Jr. Member
  • **
  • Posts: 83
  • Karma: +2/-1
  • A student of university and creator of LHMP.
    • View Profile
    • LHMP
Re: Using 'loops' in a Class
« Reply #1 on: February 21, 2017, 07:40:04 pm »
I'm not an expert, but I'll try to give you my opinion.

In history, the computer science has been through several approaches called paradigms which define how parts of program are viewed and act.
From the point of theory, these paradimgs may use different mechanism to compute (for instance, OOP objects would use message sending to communicate) and may not use instructions (non-imperative languages such as LISP,Prolog).

These approaches are used in real, but their implementation migh differ from "clean" theoretic view. As for OOP in real programs, it depends a bit on language you are using.
In C++ which is still close to CPU (from the point of abstraction), objects are treated as data structures with methods - functions. Thus, in C++, selection, sequence and iteration are rather neccessary to use to program anything, even while using classes.

Although using loops in class is correct if neccessary, modern C++ may provide bunch of standard alternatives which will keep the abstraction of your code high (for example, iterating through vectors or data structures).

In conclusion, the usage of language mechanisms depends on your experience with language and programming, and on specific situations.
« Last Edit: February 21, 2017, 09:00:06 pm by Romop5 »


© Liberty Unleashed Team.