Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. do while until end of array
Forum Updated to NodeBB v4.3 + New Features

do while until end of array

Scheduled Pinned Locked Moved Solved C++ Gurus
8 Posts 4 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Natural_Bugger
    wrote on last edited by Natural_Bugger
    #1

    how to use a Do While until of array?

        constexpr int n = 9;
        char grid[n][n];
       
        auto it=std::begin(grid);
    
        do {
            *(*it+1) = 'S'; // all fine
        } while (*it != end); // doesn't compile
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bagavathi
      wrote on last edited by
      #2

      @Natural_Bugger said in do while until end of array:

      end

      What do you mean by 'end' ?

      I hope, it should be std::end(grid).

      N 2 Replies Last reply
      1
      • B Bagavathi

        @Natural_Bugger said in do while until end of array:

        end

        What do you mean by 'end' ?

        I hope, it should be std::end(grid).

        N Offline
        N Offline
        Natural_Bugger
        wrote on last edited by Natural_Bugger
        #3

        @Bagavathi

        Thnx, but i tried that already.
        well, i just want to loop of the length over the array.

        constexpr int n = 9;
            char grid[n][n];
           
            auto it=std::begin(grid);
        
        do {
                    *(*it+1) = 'S';
                } while (*it != std::end(grid));
        

        result in:

        error: comparison between distinct pointer types β€˜char*’ and β€˜char (*)[9]’ lacks a cast [-fpermissive]
           71 |         } while (*it != std::end(grid));
              |                                      ^
        error: comparison of distinct pointer types ('char *' and 'char *[9]')
        
        1 Reply Last reply
        0
        • B Bagavathi

          @Natural_Bugger said in do while until end of array:

          end

          What do you mean by 'end' ?

          I hope, it should be std::end(grid).

          N Offline
          N Offline
          Natural_Bugger
          wrote on last edited by
          #4

          @Bagavathi

          hehe

          do {
                      *(*it+1) = 'S';
                  } while (it != std::end(grid));
          

          i remove the "*" before "it" and it worked out.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Natural_Bugger
            wrote on last edited by
            #5

            error, it does compile.
            but the code doesn't work.
            no indication of error, it just doesn't do anything and doesn't execute the code below the "Do While" loop.

            J.HilkJ 1 Reply Last reply
            0
            • N Natural_Bugger

              error, it does compile.
              but the code doesn't work.
              no indication of error, it just doesn't do anything and doesn't execute the code below the "Do While" loop.

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Natural_Bugger
              If only there was a function that would take any container and iterate over all its values πŸ€”
              oh!
              right:

              constexpr int n = 9;
                      char grid[n][n];
              
                      for( auto c : grid){
                          qDebug() << c;
                      }
              

              πŸ˜‰


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              N 1 Reply Last reply
              4
              • J.HilkJ J.Hilk

                @Natural_Bugger
                If only there was a function that would take any container and iterate over all its values πŸ€”
                oh!
                right:

                constexpr int n = 9;
                        char grid[n][n];
                
                        for( auto c : grid){
                            qDebug() << c;
                        }
                

                πŸ˜‰

                N Offline
                N Offline
                Natural_Bugger
                wrote on last edited by Natural_Bugger
                #7

                @J-Hilk

                Thnx, i have multiple different "style" for loops in my source file going over the same array, all good.
                i just wanted to try a "Do While", i don't need to access it values "perse", just stop at the end.

                1 Reply Last reply
                0
                • GerhardG Offline
                  GerhardG Offline
                  Gerhard
                  wrote on last edited by
                  #8

                  Hi,
                  this
                  do {
                  *(*it+1) = 'S';
                  } while (it != std::end(grid));
                  doesn't never end because the iterator is not incremented! (endless loop)

                  Gerhard

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved