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

  • Home
  • SEARCH
  • 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 8815777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:27:39+00:00 2026-06-14T04:27:39+00:00

I am new to programming in general and I find myself depending too much

  • 0

I am new to programming in general and I find myself depending too much on conditional statements. I find them similar to my train of thought when coding which makes them easy to implement.

Below I have a small code snippet in Verilog which controls a digital clock display. The entire code is pretty much laid out in this way. The code works and is pretty readable. However, I find it to be inelegant. Is it possible to simplify the code while at the same time improving readability?

    if (cnt >= clkspeed) begin
        cnt = 0;
        out0 <= out0 + 4'h1;

        // LED0 > 9 -> LED1 += 1
        if (out0 == 4'h9) begin
            out0 <= 4'h0;
            out1 <= out1 + 4'h1;

            // LED1 > 5 -> LED2 += 1
            if (out1 == 4'h5) begin
                out1 <= 4'h0;
                out2 <= out2 + 4'h1;

                // LED2 > 9 -> LED3 += 1
                if (out2 == 4'h9) begin
                    out2 <= 4'h0;
                    out3 <= out3 + 4'h1;

                    // LED3 > 5 -> LED3 = 0
                    if (out3 == 4'h5) begin
                        out3 <= 4'h0;
                    end                     
                end
            end
        end
    end
  • 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-14T04:27:41+00:00Added an answer on June 14, 2026 at 4:27 am

    Your problem here is that you perform the same operation four times, as you store your data in scalar variables. The solution for this case would be to store the numbers in an array, and loop through them. The pseudocode of this is something like:

    array<int> digits;
    int position = digits.length();
    while (position >= 0) {
        digits[position] = (digits[position] + 1) % 10;
        if (digits[position]>0) break; // if there is no carry, just break
        position--;
    }
    

    This code assumes that every digit counts up to 9. So you still have to add the logic for handling LED1 and LED3… (Through using another array, or if you have OOP creating a LED object which can store the actual number and the limit for the led…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to programming in general so please keep that in mind when
I am very new to programming in general, while reading about PHP I saw
I'm new to web programming in general so this is probably a really simple
Brand new to Python (and programming in general), if this is simple and/or answered
I'm new to Python and to programming in general. I've installed BioPython in hopes
I'm new to Django and Web programming in general. Have googled but could not
I'm pretty new to Python and programming in general, and I was wondering if
I'm fairly new to Java and Android programming in general but I would like
I am new to Javascript and object-oriented programming in general. I would like to
I am fairly new to iphone development and programming in general and am wondering

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.