Documentation

    Table of Content
    • CodePorting.Native Product Family
      • CodePorting.Native Cs2Cpp
        • Getting Started
          • Product Overview
          • Installation
          • Licensing
          • How to use CodePorting.Native Cs2Cpp
            • How to Use Command line to port and build Projects
            • How to Use GUI to port and build Projects
        • Developer Guide
          • Porting Simple C# Projects
            • Porting Simple Console Application
            • Porting Simple Library
            • Porting Simple NUnit Test
          • Porting Dependent C# Projects
            • Porting Dependent Console Application
            • Porting Dependent Library
            • Porting Dependent NUnit Test
          • Porting Complex C# Projects
            • How to Convert Complex C# Console Application to C++
            • How to Convert Complex C# Library to C++
            • How to Convert Complex C# NUnit Test to C++
          • Qt support
          • What Converts to What
            • AbstractClasses
            • BreakStatements
            • ClassAutoProperties
            • ClassConstructors
            • ClassEvents
            • ClassFinalizers
            • ClassGenericMethods
            • ClassIndexers
            • ClassMethods
            • ClassProperties
            • ClassStaticConstructor
            • ClassStaticMethods
            • ClassStaticProperties
            • ClassVirtualMethods
            • ContinueStatements
            • Delegates
            • DoWhileStatements
            • Enums
            • EnumTypeCast
            • Exceptions
            • ExpectedException
            • ForeachStatements
            • ForeachStatementsStd
            • ForStatements
            • GenericClasses
            • GenericDelegates
            • GenericInterfaces
            • GenericStructs
            • IfStatements
            • LambdaExpressions
            • NestedClasses
            • ReturnStatements
            • SimpleClass
            • SimpleInterface
            • SimpleStruct
            • SimpleTest
            • StandardTypeCast
            • StaticClass
            • SwitchStatements
            • TestWithSetupMethods
            • ThrowStatements
            • TryCatchFinallyStatements
            • TryCatchStatements
            • TryFinallyStatements
            • VarExpressions
            • WhileStatements
          • CodePorting Native Cs2Cpp Attributes
          • CodePorting Native Cs2Cpp Configuration File
            • CodePorting.Native Cs2Cpp Configuration File Structure
            • Attributes in Configuration file
            • Configuration file Nodes
            • Configuration file Options
          • Memory Management Model
            • Memory Management Model Description
            • Using aliasing constructor to create a smart pointer
          • Cmake Support
          • C++ code injection
          • C++ user-defined exception classes
          • Limitations and Bugs
            • Porter Limitations and Bugs
            • Library Limitations and Bugs
            • Cpp Code Injection
        • Release Notes
          • 2022
            • CodePorting.Native Cs2Cpp 22.5
            • CodePorting.Native Cs2Cpp 22.4
            • CodePorting.Native Cs2Cpp 22.3
            • CodePorting.Native Cs2Cpp 22.2
            • CodePorting.Native Cs2Cpp 22.1
          • 2021
            • CodePorting.Native Cs2Cpp 21.12
            • CodePorting.Native Cs2Cpp 21.11
            • CodePorting.Native Cs2Cpp 21.10.1
            • CodePorting.Native Cs2Cpp 21.10
            • CodePorting.Native Cs2Cpp 21.9
            • CodePorting.Native Cs2Cpp 21.8
            • CodePorting.Native Cs2Cpp 21.7
            • CodePorting.Native Cs2Cpp 21.6
            • CodePorting.Native Cs2Cpp 21.5
            • CodePorting.Native Cs2Cpp 21.4
            • CodePorting.Native Cs2Cpp 21.3
            • CodePorting.Native Cs2Cpp 21.2
            • CodePorting.Native Cs2Cpp 21.1
          • 2020
            • CodePorting.Native Cs2Cpp 20.12
            • CodePorting.Native Cs2Cpp 20.11
            • CodePorting.Native Cs2Cpp 20.10
            • CodePorting.Native Cs2Cpp 20.9
            • CodePorting.Native Cs2Cpp 20.8
            • CodePorting.Native Cs2Cpp 20.7
            • CodePorting.Native Cs2Cpp 20.6
            • CodePorting.Native Cs2Cpp 20.5
            • CodePorting.Native Cs2Cpp 20.4
            • CodePorting.Native Cs2Cpp 20.3
            • CodePorting.Native Cs2Cpp 20.2
            • CodePorting.Native Cs2Cpp 20.1
          • 2019
            • CodePorting.Native Cs2Cpp 19.1
            • CodePorting.Native Cs2Cpp 19.2
            • CodePorting.Native Cs2Cpp 19.3
            • CodePorting.Native Cs2Cpp 19.4
            • CodePorting.Native Cs2Cpp 19.4.1
            • CodePorting.Native Cs2Cpp 19.5
            • CodePorting.Native Cs2Cpp 19.6
            • CodePorting.Native Cs2Cpp 19.7
            • CodePorting.Native Cs2Cpp 19.8
            • CodePorting.Native Cs2Cpp 19.9
            • CodePorting.Native Cs2Cpp 19.10
            • CodePorting.Native Cs2Cpp 19.11
            • CodePorting.Native Cs2Cpp 19.12
          • 2018
            • CodePorting.Native Cs2Cpp 18.9
            • CodePorting.Native Cs2Cpp 18.9.1
            • CodePorting.Native Cs2Cpp 18.10
            • CodePorting.Native Cs2Cpp 18.11
            • CodePorting.Native Cs2Cpp 18.12
    1. Home
    2. CodePorting.Native Product Family
    3. CodePorting.Native Cs2Cpp
    4. Developer Guide
    5. What Converts to What
    6. BreakStatements

    BreakStatements

    What's on this Page

      • Source C# Code
      • Ported Code
        • C++ Header
        • C++ Source Code

    This example demonstrates how break statement inside loop is ported to C++.

    Additional command-line options passed to CsToCppPorter: none.

    Source C# Code

    using System;
    
    namespace StatementsPorting
    {
        public class BreakStatements
        {
            public void BreakForeach(int[] values, int max)
            {
                foreach (int value in values)
                {
                    Console.WriteLine(value);
                    if (value > max)
                        break;
                }
            }
    
            public void BreakEnclosedForeach(int[][] values, int max)
            {
                foreach (int[] row in values)
                {
                    if (row.Length == 0)
                        break;
                    foreach (int value in row)
                    {
                        Console.WriteLine(value);
                        if (value > max)
                            break;
                    }
                }
            }
    
            public void BreakFor(int max)
            {
                for (int index = 0; index < max; ++index)
                {
                    Console.WriteLine(index);
                    if (index % 5 == 4)
                        break;
                }
            }
    
            public void BreakEnclosedFor(int max1, int max2)
            {
                for (int index1 = 0; index1 < max1; ++index1)
                {
                    if (index1 % 14 == 11)
                        break;
                    for (int index2 = 0; index2 < max2; ++index2)
                    {
                        Console.WriteLine(index1 + index2);
                        if (index2 % 13 == 7)
                            break;
                    }
                }
            }
    
            public void BreakWhile(int max)
            {
                int number = 0;
                while (number < max)
                {
                    Console.WriteLine(number);
                    if (number % 5 == 4)
                        break;
                    ++number;
                }
            }
    
            public void BreakEnclosedWhile(int max1, int max2)
            {
                int number1 = 0;
                while (number1 < max1)
                {
                    if (number1 % 14 == 11)
                        break;
                    int number2 = 0;
                    while (number2 < max2)
                    {
                        Console.WriteLine(number1 + number2);
                        if (number2 % 5 == 4)
                            break;
                        ++number2;
                    }
                    ++number1;
                }
            }
    
            public void BreakDoWhile(int max)
            {
                int number = 0;
                do
                {
                    Console.WriteLine(number);
                    if (number % 5 == 4)
                        break;
                    ++number;
                } while (number < max);
            }
    
            public void BreakEnclosedDoWhile(int max1, int max2)
            {
                int number1 = 0;
                do
                {
                    if (number1 % 14 == 11)
                        break;
                    int number2 = 0;
                    do
                    {
                        Console.WriteLine(number1 + number2);
                        if (number2 % 5 == 4)
                            break;
                        ++number2;
                    } while (number2 < max2);
                    ++number1;
                } while (number1 < max1);
            }
        }
    }

    Ported Code

    C++ Header

    #pragma once
    
    #include <system/array.h>
    #include <cstdint>
    
    namespace StatementsPorting {
    
    class BreakStatements : public System::Object
    {
        typedef BreakStatements ThisType;
        typedef System::Object BaseType;
        
        typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
        RTTI_INFO_DECL();
        
    public:
    
        void BreakForeach(System::ArrayPtr<int32_t> values, int32_t max);
        void BreakEnclosedForeach(System::ArrayPtr<System::ArrayPtr<int32_t>> values, int32_t max);
        void BreakFor(int32_t max);
        void BreakEnclosedFor(int32_t max1, int32_t max2);
        void BreakWhile(int32_t max);
        void BreakEnclosedWhile(int32_t max1, int32_t max2);
        void BreakDoWhile(int32_t max);
        void BreakEnclosedDoWhile(int32_t max1, int32_t max2);
        
    };
    
    } // namespace StatementsPorting
    

    C++ Source Code

    #include "BreakStatements.h"
    
    #include <system/console.h>
    
    namespace StatementsPorting {
    
    RTTI_INFO_IMPL_HASH(409202246u, ::StatementsPorting::BreakStatements, ThisTypeBaseTypesInfo);
    
    void BreakStatements::BreakForeach(System::ArrayPtr<int32_t> values, int32_t max)
    {
        for (int32_t value : values)
        {
            System::Console::WriteLine(value);
            if (value > max)
            {
                break;
            }
        }
        
    }
    
    void BreakStatements::BreakEnclosedForeach(System::ArrayPtr<System::ArrayPtr<int32_t>> values, int32_t max)
    {
        for (System::ArrayPtr<int32_t> row : values)
        {
            if (row->get_Length() == 0)
            {
                break;
            }
            
            {
                for (int32_t value : row)
                {
                    System::Console::WriteLine(value);
                    if (value > max)
                    {
                        break;
                    }
                }
                
            }
        }
        
    }
    
    void BreakStatements::BreakFor(int32_t max)
    {
        for (int32_t index = 0; index < max; ++index)
        {
            System::Console::WriteLine(index);
            if (index % 5 == 4)
            {
                break;
            }
        }
    }
    
    void BreakStatements::BreakEnclosedFor(int32_t max1, int32_t max2)
    {
        for (int32_t index1 = 0; index1 < max1; ++index1)
        {
            if (index1 % 14 == 11)
            {
                break;
            }
            for (int32_t index2 = 0; index2 < max2; ++index2)
            {
                System::Console::WriteLine(index1 + index2);
                if (index2 % 13 == 7)
                {
                    break;
                }
            }
        }
    }
    
    void BreakStatements::BreakWhile(int32_t max)
    {
        int32_t number = 0;
        while (number < max)
        {
            System::Console::WriteLine(number);
            if (number % 5 == 4)
            {
                break;
            }
            ++number;
        }
    }
    
    void BreakStatements::BreakEnclosedWhile(int32_t max1, int32_t max2)
    {
        int32_t number1 = 0;
        while (number1 < max1)
        {
            if (number1 % 14 == 11)
            {
                break;
            }
            int32_t number2 = 0;
            while (number2 < max2)
            {
                System::Console::WriteLine(number1 + number2);
                if (number2 % 5 == 4)
                {
                    break;
                }
                ++number2;
            }
            ++number1;
        }
    }
    
    void BreakStatements::BreakDoWhile(int32_t max)
    {
        int32_t number = 0;
        do
        {
            System::Console::WriteLine(number);
            if (number % 5 == 4)
            {
                break;
            }
            ++number;
        } while (number < max);
    }
    
    void BreakStatements::BreakEnclosedDoWhile(int32_t max1, int32_t max2)
    {
        int32_t number1 = 0;
        do
        {
            if (number1 % 14 == 11)
            {
                break;
            }
            int32_t number2 = 0;
            do
            {
                System::Console::WriteLine(number1 + number2);
                if (number2 % 5 == 4)
                {
                    break;
                }
                ++number2;
            } while (number2 < max2);
            ++number1;
        } while (number1 < max1);
    }
    
    } // namespace StatementsPorting