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 16 Aug 2020, 10:02 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 16 Aug 2020, 10:08 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 16 Aug 2020, 10:13
      1
      • B Bagavathi
        16 Aug 2020, 10:08

        @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 16 Aug 2020, 10:13 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
          16 Aug 2020, 10:08

          @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 16 Aug 2020, 10:17 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 16 Aug 2020, 10:21 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 1 Reply Last reply 16 Aug 2020, 10:29
            0
            • N Natural_Bugger
              16 Aug 2020, 10:21

              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 Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 16 Aug 2020, 10:29 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 16 Aug 2020, 10:35
              4
              • J J.Hilk
                16 Aug 2020, 10:29

                @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 16 Aug 2020, 10:35 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 16 Aug 2020, 15:54 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

                  1/8

                  16 Aug 2020, 10:02

                  • Login

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